package com.aaa.a1102.demo01;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author 荆豪峰
 * @version 1.0
 */
public class Test01 {
    public static void main(String[] args) {
        //创建单一线程池
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        //创建固定长度的线程池
        ExecutorService executorService1 = Executors.newFixedThreadPool(5);
        //创建可变长度的线程池
        ExecutorService executorService2 = Executors.newCachedThreadPool();

        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
        for (int i = 0; i < 20;i++) {
            final int a = i;
            scheduledExecutorService.schedule(new Runnable() {
                public void run() {
                    System.out.println(Thread.currentThread().getName() + "========"+a);
                }
            } ,20, TimeUnit.SECONDS);
}


       /* for (int i = 0; i < 10;i++) {
            final int a = i;
            executorService.submit(new Runnable() {
                public void run() {
                    System.out.println(Thread.currentThread().getName() + "========"+a);
                }
            });
     }*/
    }
}
